# 构建阶段
FROM node:18 AS build-stage

# 设置工作目录
WORKDIR /app

# 复制package.json和package-lock.json
COPY package*.json ./

# 安装依赖 - 使用国内镜像源
RUN npm config set registry https://registry.npmmirror.com && npm install

# 复制源代码
COPY . .

# 构建应用 - 使用NODE_OPTIONS解决OpenSSL兼容性问题
RUN NODE_OPTIONS=--openssl-legacy-provider npm run build:prod

# 生产阶段
FROM nginx:alpine AS production-stage

# 复制构建产物到nginx目录
COPY --from=build-stage /app/dist /usr/share/nginx/html

# 复制nginx配置文件
COPY nginx.conf /etc/nginx/nginx.conf

# 暴露端口
EXPOSE 80

# 启动nginx
CMD ["nginx", "-g", "daemon off;"] 